package com.example.demo.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.STitle;
import com.example.demo.common.utils.Response;
import com.example.demo.service.STitleService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "职位信息服务")
@RestController
@RequestMapping("/title")
public class STitleController {
	@Autowired
	private STitleService stService;

	@GetMapping("/all")
	@ApiOperation(value = "查找所有职位信息",notes="分页显示所有职位信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageNum",value = "页码",defaultValue = "1"),	@ApiImplicitParam(name="pageSize",value = "每页显示个数",defaultValue = "3")	
	})
	public Response findAll(@RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "3")int pageSize) {
		return Response.success(stService.findAllByPage(pageNum, pageSize));
	}
	@GetMapping("/title")
	@ApiOperation(value = "通过名字查找信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageNum",value = "页码",defaultValue = "1"),	@ApiImplicitParam(name="pageSize",value = "每页显示个数",defaultValue = "3")	
	})
	public Response findByName(String title,@RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "3")int pageSize) {
		return Response.success(stService.findByName(title, pageNum, pageSize));
	}
	@PostMapping("/save")
	@ApiOperation(value = "添加职位")
	public Response saveTitle(STitle st) {
		stService.saveTitle(st);
		return Response.success(stService.saveTitle(st));
	}
	@DeleteMapping("/delete")
	@ApiOperation(value = "删除职位信息")
	public Response deleteByTitle(String title) {
		stService.deleteByTitle(title);
		return Response.success("删除成功");
	}
	@DeleteMapping("/batchdelete")
	@ApiOperation(value = "批量删除")
	public Response batchDelete(String [] title) {
		stService.batchDelete(title);
		return Response.success("删除成功");
	}
}
